import numpy as np
import matplotlib.pyplot as plt


def derivative_demo1():
    """
    对于x的三次方，求一阶导、二阶导
    :return:
    """
    x = np.linspace(-10, 10, num=500)
    y = x ** 3

    first_derivative = 3 * x ** 2
    second_derivative = 6 * x

    plt.plot(x, y, label="函数")
    plt.plot(x, first_derivative, label="一阶导")
    plt.plot(x, second_derivative, label='二阶导')

    plt.legend(loc="best")  # label 放置位置
    plt.rcParams['font.sans-serif'] = ['SimHei']  # 解决中文乱码问题
    plt.rcParams['axes.unicode_minus'] = False  # 解决负号不显示

    plt.show()


if __name__ == '__main__':
    derivative_demo1()
